package cn.imvc.app.controllers;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.imvc.app.entities.Dealer;
import cn.imvc.app.models.DealerModel;

@Controller
public class AppControllerImpl implements AppController {

	@Autowired
	DealerModel dealerModel;
	
	@RequestMapping("/app.html")
	public String app(HttpServletRequest request, Model model){
		String serverName = request.getServerName();
		String[] www = serverName.split("\\.");
		if (www.length == 3 && !"www".equals(www[0])) {
			String domain = www[0];
			Dealer dealer = dealerModel.getByDomain(domain);
			if (dealer != null) {
				model.addAttribute("domain", domain);
			}
		}
		return "app/app";
	}
	
	@RequestMapping("/ios.html")
	public String ios(Model model) {
		return "app/ios";
	}

}
